package com.cloudea.lotus;

import java.util.Objects;

/**
 * 统一的响应对象
 */
public class Response {
    private int code = 0;
    private String message = "";
    private Object data = null;

    public Response(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static Response success(){
        return new Response(0, "操作成功", null);
    }

    public static Response success(Object data){
        return new Response(0, "操作成功", data);
    }

    public static Response fail(String message){
        return new Response(1, message, null);
    }

    public static Response fail(int code, String message){
        return new Response(code, message, null);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Response response = (Response) o;
        return code == response.code &&
                (message == null && response.message == null || message != null && message.equals(response.message)) &&
                (data == null && response.data == null || data != null && data.equals(response.data));
    }
}
